#!/bin/bash

if [[ $# -gt 2 ]] ||
   [[ $# -lt 1 ]]; then
	echo "Usage:   nginx.sh -s reload"
	echo "         nginx.sh -t"
	exit
elif [[ $# -eq 1 ]] && [[ $1 = "-t" ]]; then
	echo "[`date +"%Y-%m-%d %H:%M:%S"`] Nginx Plus checking configuration files' syntax ..."
	nginx -t
	echo "[`date +"%Y-%m-%d %H:%M:%S"`] Proxy Server(1)'172.24.16.31' checked."
	ssh root@proxy02 "nginx -t"
	echo "[`date +"%Y-%m-%d %H:%M:%S"`] Proxy Server(2)'172.24.16.30' checked."
elif [[ $# -eq 2 ]] && [[ $1 = "-s" ]] && [[ $2 = "reload" ]]; then
	echo "[`date +"%Y-%m-%d %H:%M:%S"`] Nginx Plus reload configurations ..."
	nginx -s reload
	echo "[`date +"%Y-%m-%d %H:%M:%S"`] Proxy Server(1)'172.24.16.31' reloaded."
	ssh root@proxy02 "nginx -s reload"
	echo "[`date +"%Y-%m-%d %H:%M:%S"`] Proxy Server(2)'172.24.16.30' reloaded."
else
	echo "command argument wrong!"
        echo "Usage:   nginx.sh -s reload"
        echo "         nginx.sh -t"	
	exit
fi
